﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;

namespace login
{
    [DataContractAttribute]
    class UserInfoModel
    {
        public UserInfoModel()
        {
        }
            
        [DataMember]
        public bool Gender { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public DateTime Birth { get; set; }
        [DataMember]
        public int HealthState { get; set; }
        [DataMember]
        public bool MarriageState { get; set; }
        [DataMember]
        public string BirthPlace { get; set; }
        [DataMember]
        public int EducationLevel { get; set; }
        [DataMember]
        public int PolicitalStatus { get; set; }
        [DataMember]
        public string IDNumber { get; set; }
        [DataMember]
        public string AddressHometown { get; set; }
        [DataMember]
        public string AddressNow { get; set; }
        [DataMember]
        public string Telephone { get; set; }
        [DataMember]
        public int Privilege { get; set; }
        [DataMember]
        public byte[] IndexFinger { get; set; }
        [DataMember]
        public byte[] MiddleFinger { get; set; }
        [DataMember]
        public byte[] RingFinger { get; set; }
        [DataMember]
        public byte[] HeadPortrait { get; set; }


        public string EntityToJson(UserInfoModel entity)
        {
            DataContractSerializer serializer = new DataContractSerializer(entity.GetType());
            using (MemoryStream stream = new MemoryStream())
            {
                serializer.WriteObject(stream, entity);
                return Encoding.UTF8.GetString(stream.ToArray());
            }

        }

        public UserInfoModel JsonToEntity(string jsonstring)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(UserInfoModel));
            using (MemoryStream mStream = new MemoryStream(Encoding.UTF8.GetBytes(jsonstring)))
            {
                return serializer.ReadObject(mStream) as UserInfoModel;
            }
        }
    }
}
